package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.voyagebsahgvo.VoyageBsaHgCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsahgvo.VoyageBsaHgPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsahgvo.VoyageBsaHgRespVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsahgvo.VoyageBsaHgUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmc.cloud.cmclink.doc.entity.VoyageBsaHgDO;
import com.cmc.cloud.cmclink.doc.service.VoyageBsaHgService;


/**
 * 高箱计算标准前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 高箱计算标准")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/bsaHg")
public class VoyageBsaHgController {

    @Resource
    private VoyageBsaHgService voyageBsaHgService;

    @Operation(summary = "创建高箱计算标准")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission({'doc:setupBSAExport:Others:add','doc:setupBSAImport:Others:add','doc:setupBSAExportTemplate:Others:add','doc:setupBSAImportTemplate:Others:add'})")
    public CommonResult<Void> createVoyageBsaHg(@Valid @RequestBody VoyageBsaHgCreateReqVO createReqVO) {
        voyageBsaHgService.createVoyageBsaHg(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新高箱计算标准")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission({'doc:setupBSAExport:Others:edit','doc:setupBSAImport:Others:edit','doc:setupBSAExportTemplate:Others:edit','doc:setupBSAImportTemplate:Others:edit'})")
    public CommonResult<Void> updateVoyageBsaHg(@Valid @RequestBody VoyageBsaHgUpdateReqVO updateReqVO) {
        voyageBsaHgService.updateVoyageBsaHg(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除高箱计算标准")
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission({'doc:setupBSAExport:Others:delete','doc:setupBSAImport:Others:delete','doc:setupBSAExportTemplate:Others:delete','doc:setupBSAImportTemplate:Others:delete'})")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteVoyageBsaHg(@PathVariable("id") Long id) {
        voyageBsaHgService.deleteVoyageBsaHg(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得高箱计算标准")
    @GetMapping("/getById/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<VoyageBsaHgRespVO> getVoyageBsaHg(@PathVariable("id") Long id) {
        VoyageBsaHgDO voyageBsaHg = voyageBsaHgService.getVoyageBsaHg(id);
        return CommonResult.success(BeanUtil.copyProperties(voyageBsaHg, VoyageBsaHgRespVO.class));
    }

    @Operation(summary = "根据主信息id获得高箱计算标准")
    @GetMapping("/getByMainId/{mainId}")
    @UseResponsePropertyAdvice
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<List<VoyageBsaHgRespVO>> getByMainId(@PathVariable("mainId") Long id) {
        List<VoyageBsaHgDO> voyageBsaHgDos = voyageBsaHgService.getVoyageBsaHgByMainId(id);
        return CommonResult.success(BeanUtil.copyToList(voyageBsaHgDos, VoyageBsaHgRespVO.class));
    }

    @Operation(summary = "获得高箱计算标准列表")
    @GetMapping("/listAll")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('doc:voyage-bsa-hg:query')")
    public CommonResult<List<VoyageBsaHgRespVO>> getVoyageBsaHgList(@RequestParam("ids") Collection<Long> ids) {
        List<VoyageBsaHgDO> list = voyageBsaHgService.getVoyageBsaHgList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, VoyageBsaHgRespVO.class));
    }

    @Operation(summary = "获得高箱计算标准分页")
    @PostMapping("/getPage")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<VoyageBsaHgRespVO>> getVoyageBsaHgPage(@Valid @RequestBody VoyageBsaHgPageReqVO pageVO) {
        PageResult<VoyageBsaHgDO> pageResult = voyageBsaHgService.getVoyageBsaHgPage(pageVO);
        List<VoyageBsaHgRespVO> results = BeanUtil.copyToList(pageResult.getList(), VoyageBsaHgRespVO.class);
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
